package edu.fim.presentation.model.bean;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import edu.fim.data.Identifiable;

@Entity
@Table(name = "tb_foods")
public class Food implements Identifiable<Integer> {

	private static final long serialVersionUID = -5752351117955577287L;

	private Integer id;
	private String name;
	private Double calories;
	private Double dailyValue;
	private List<Consumer> consumers;

	public Food() {
	}
	
	public Food(
			Integer id,
			String nome,
			Double calorias) {
		this.id = id;
		this.name = nome;
		this.calories = calorias;
	}

	@Id
	@Column(name = "id")
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	@Column(name = "name")
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "calories")
	public Double getCalories() {
		return calories;
	}

	public void setCalories(Double calories) {
		this.calories = calories;
	}
	
	public Double getDailyValue() {
		return dailyValue;
	}

	public void setDailyValue(Double dailyValue) {
		this.dailyValue = dailyValue;
	}

	@ManyToMany
	@JoinTable(
			name = "tb_preferences",
			joinColumns = { @JoinColumn(name = "idFood") },
			inverseJoinColumns = { @JoinColumn(name = "idConsumer") }
	)
	public List<Consumer> getConsumers() {
		return consumers;
	}

	public void setConsumers(List<Consumer> consumers) {
		this.consumers = consumers;
	}

	@Override
	public String toString() {
		return name + ": " + calories + "cal";
	}
}